package demo.blog.controller.vo;

import demo.blog.model.User;
import lombok.Data;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import java.util.Optional;

@Data
public class UserEnrollVo {
    @NotEmpty(message = "邮箱不能为空")
    @Email(message = "邮箱格式错误")
    private String email;
    @NotEmpty(message = "密码不能为空")
    //@Min(value = 8,message = "密码简单")
    private String password;
    private String nickname;
    @NotEmpty(message = "邀请码不能为空")
    private String invite;

    public User toUser(){
        User user = new User();
        user.setEmail(this.email);
        user.setPassword(this.password);
        Optional<String> optionalS = Optional.ofNullable(this.nickname);
        user.setNickname(optionalS.orElse(this.email));
        return user;
    }

}
